using System;
using System.Web.UI;
using SharpPieces.Web.Controls;

namespace SharpPieces.DemoApp
{

    /// <summary>
    /// The LiveGrid Options page.
    /// </summary>
    public partial class LiveGridOptions : Page
    {

        // Methods

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"/> object that contains the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            //this.Master.AddCodePreview(this.Page.MapPath("~/Code/OptionsDataProvider.cs"));
            //this.Master.AddCodePreview(this.Page.MapPath(
               //string.Format("~/App_Themes/{0}/livegrid/grid-default.css", this.Theme)));

            if (!this.IsPostBack)
            {
                this.OptionsToGrid();
            }
        }

        /// <summary>
        /// Handles the Click event of the Button1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            this.OptionsToGrid();
        }

        private void OptionsToGrid()
        {
            this.LiveGrid1.Highlight =
                (HighlightType)Enum.Parse(typeof(HighlightType), this.DropDownList2.SelectedValue);
            this.LiveGrid1.AllowGrouping = this.CheckBox7.Checked;
            this.LiveGrid1.AllowResizing = this.CheckBox2.Checked;
            this.LiveGrid1.Bookmarking.AllowBookmarking = this.CheckBox6.Checked;
            this.LiveGrid1.Bookmarking.AllowBookmarkScroll = this.CheckBox3.Checked;
            this.LiveGrid1.Bookmarking.BookmarkExpression = this.TextBox1.Text;
            this.LiveGrid1.Bookmarking.BookmarkPosition =
                (this.CheckBox4.Checked) ? BookmarkPosition.Top : BookmarkPosition.Bottom;
            this.LiveGrid1.Sorting.AllowSorting = this.CheckBox1.Checked;
            this.LiveGrid1.VisibleRows = int.Parse(this.DropDownList1.SelectedValue);
            this.LiveGrid1.IsIndexed = this.CheckBox8.Checked;

            // columns

            this.LiveGrid1.Columns[0].HeaderText = this.TextBox2.Text;
            this.LiveGrid1.Columns[0].AllowResizing = this.CheckBox5.Checked;
            this.LiveGrid1.Columns[0].AllowSorting = this.CheckBox9.Checked;
            this.LiveGrid1.Columns[0].Grouping.GroupingType =
                (LiveGridColumn.ColumnGroupingType)Enum.Parse(typeof(LiveGridColumn.ColumnGroupingType),
                    this.DropDownList3.SelectedValue);
            this.LiveGrid1.Columns[0].Grouping.GroupText = this.TextBox3.Text;

            this.LiveGrid1.Columns[1].HeaderText = this.TextBox4.Text;
            this.LiveGrid1.Columns[1].AllowResizing = this.CheckBox10.Checked;
            this.LiveGrid1.Columns[1].AllowSorting = this.CheckBox11.Checked;
            this.LiveGrid1.Columns[1].Grouping.GroupingType =
                (LiveGridColumn.ColumnGroupingType)Enum.Parse(typeof(LiveGridColumn.ColumnGroupingType),
                    this.DropDownList4.SelectedValue);
            this.LiveGrid1.Columns[1].Grouping.GroupText = this.TextBox7.Text;

            this.LiveGrid1.Columns[2].HeaderText = this.TextBox8.Text;
            this.LiveGrid1.Columns[2].AllowResizing = this.CheckBox12.Checked;
            this.LiveGrid1.Columns[2].AllowSorting = this.CheckBox13.Checked;
            this.LiveGrid1.Columns[2].Grouping.GroupingType =
                (LiveGridColumn.ColumnGroupingType)Enum.Parse(typeof(LiveGridColumn.ColumnGroupingType),
                    this.DropDownList5.SelectedValue);
            this.LiveGrid1.Columns[2].Grouping.GroupText = this.TextBox10.Text;
        }

    }

}